/**
 * 登录框
 * 
 * @author luo
 * @email luo4521@online.net.tw
 * 2010-1-28 10:34
 */
package com.addcn.demo.view.components
{
	import flash.display.MovieClip;
	import flash.display.*;
	import flash.events.*;
	import flash.text.TextField;
	
	import com.addcn.demo.event.paramEvent;
	
	public class loginBox extends winBase
	{
		public static const LOGIN_EVENT : String = 'loginEvent';
		
		function loginBox (_parent : Object) : void {	
			if (_parent == null) return;			
			_parent.addChild(this);			
			this.x = (_parent.stage.stageWidth -this.width)/ 2;
			this.y = (_parent.stage.stageHeight - this.height) / 3;						
			this.drag(this['bg']);
			this["login_btn"].addEventListener(MouseEvent.CLICK, login_btnClickHandler);				
		}		
		
		private function login_btnClickHandler(evt : Event) : void {
			if ( !this["acc_input"].text) {
				this["notice_tf"].text = '请输入帐号';
				this.stage.focus = this["acc_input"];
			}else if (!this["pwd_input"].text) {
				this["notice_tf"].text = '请输入密码';
				this.stage.focus = this["pwd_input"];
			}else {
				this["notice_tf"].text = '';				
				var _params : Object = new Object;
				_params.acc = this["acc_input"].text;
				_params.pwd = this["pwd_input"].text;
				var event : paramEvent = new paramEvent(loginBox.LOGIN_EVENT, _params);
				this['login_btn'].enabled = false;
				this.dispatchEvent(event);
			}
			
		}
		public function reset() : void {
			this.stage.focus = this["acc_input"];
			this["pwd_input"].text = '';
			this['login_btn'].enabled = true;
		}		
		
		public function btnEnabled(bool : Boolean) : void {
			this["login_btn"].enabled = bool;
		}
		
		public override  function remove() : void {				
			super.remove();
			this["login_btn"].removeEventListener(MouseEvent.CLICK, login_btnClickHandler);
			this.parent.removeChild(this);
		}
		
		
	}
	
}
